package com.wzl.demo_06_03;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {
    MyFragment myFragment;
    SecondFragment secondFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myFragment = new MyFragment();
        secondFragment = new SecondFragment();
    }

    /*
    *   FragmentManager
        FragmentTransaction
    * */
    public void add(View view){
        getSupportFragmentManager().beginTransaction()
                .setReorderingAllowed(true)
                .add(R.id.main_container, myFragment, null)
                .commit();
    }
    public void del(View view){
        getSupportFragmentManager().beginTransaction()
                .setReorderingAllowed(true)
                .remove(myFragment)
                .commit();
    }
    public void replace(View view){
        getSupportFragmentManager().beginTransaction()
                .setReorderingAllowed(true)
                .replace(R.id.main_container, secondFragment, null)
                .commit();
    }

}